GetMeAction   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 16
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 6 1
1
import { Controller, Get, Inject, UseGuards } from '@nestjs/common';
2
import { AuthGuard } from '@nestjs/passport';
3
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
4
import { IQueryBus } from 'src/Application/IQueryBus';
5
import { GetUserByIdQuery } from 'src/Application/User/Query/GetUserByIdQuery';
6
import { UserView } from 'src/Application/User/View/UserView';
7
import { UserRole } from 'src/Domain/User/User.entity';
8
import { LoggedUser } from '../Decorator/LoggedUser';
9
import { Roles } from '../Decorator/Roles';
10
import { RolesGuard } from '../Security/RolesGuard';
11
import { UserAuthView } from '../Security/UserAuthView';
12
13
@Controller('users')
14
@ApiTags('User')
15
@ApiBearerAuth()
16
@UseGuards(AuthGuard('bearer'), RolesGuard)
17
export class GetMeAction {
18
  constructor(
19
    @Inject('IQueryBus')
20
    private readonly queryBus: IQueryBus
21
  ) {}
22
23
  @Get('me')
24
  @Roles(UserRole.PHOTOGRAPHER, UserRole.DIRECTOR)
25
  @ApiOperation({ summary: 'Get current user' })
26
  public async index(@LoggedUser() { id }: UserAuthView): Promise<UserView> {
27
    return await this.queryBus.execute(new GetUserByIdQuery(id));
28
  }
29
}
30